﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Policy;
using System.Web;
using System.Web.Mvc;
using VideoSeller.Business.Data;
using VideoSeller.Business.Data.Enums;

namespace VideoSeller.Web.Models
{
	public class PersonalViewModel : BaseViewModel
	{
		public string FirstName { get; set; }

		public string LastName { get; set; }

		public string Login { get; set; }

		public DateTime? BirthDate { get; set; }

		public List<SelectListItem> Countries { get; set; }

		public int SelectedCountryId { get; set; }

		public Country Country { get; set; }

		public Sex Sex { get; set; }

		public string About { get; set; }

		public string Address { get; set; }

		public string HomePage { get; set; }
        
        public string Culture {get; set;}
        public bool sFirstName { get; set; }
        public bool sLastName { get; set; }
        public bool sLogin { get; set; }
        public bool sBirthDate { get; set; }
        public bool sAddress { get; set; }
        //
        public int m_countAll { get; set; }
        public int m_Views_anonce {get; set;}
        public int m_Views_online {get; set;}
        public int m_Views_history { get; set; }
        public int m_like { get; set; }
        public int m_nlike { get; set; }
        public decimal m_VSM { get; set; }
        public int m_Ratin { get; set; }
        //
        public int c_countAll { get; set; }
        public int c_Views_anonce { get; set; }
        public int c_Views_online { get; set; }
        public int c_Views_history { get; set; }
        public int c_like { get; set; }
        public int c_nlike { get; set; }
        public decimal c_VSM { get; set; }
        public int c_Ratin { get; set; }
        public string language { get; set; }
        public string OnTheSite { get; set; }
        public string OldPassword { get; set; }
        public string NewPassword { get; set; }
        //
        public void LoadPersonalData(Client client, IEnumerable<Country> countries, bool iOwner)
		{
            m_countAll = client.m_countAll;
            c_countAll = client.c_countAll;
            String check = client.ShowToOther;
            sFirstName = client.sFirstName;
            sLastName = client.sLastName;
            sLogin = client.sLogin;
            sBirthDate = client.sBirthDate;
            sAddress = client.sAddress;
            Business.Models.SettingsModel _settingsModel = new Business.Models.SettingsModel();
            String hiddenText = "XXX";
            try
            {
                hiddenText = HttpContext.GetGlobalResourceObject("Common", "HiddenByOwner", CultureInfo.CurrentUICulture).ToString();
            }
            catch
            {
            }
            //HttpContext.GetGlobalResourceObject("Common", "HiddenForOther", CultureInfo.CurrentUICulture);

            if (!iOwner)
            {
                
                FirstName = sFirstName ? hiddenText : client.FirstName;
                LastName = sLastName ? hiddenText : client.LastName;
                Login = sLogin ? hiddenText : client.Login;
                BirthDate = sBirthDate ? null : client.Birthday;
                Address = sAddress ? hiddenText : client.Address;
            }
            else
            {
                FirstName = client.FirstName;
                LastName = client.LastName;
                Login = client.Login;
                BirthDate = client.Birthday;
                Address = client.Address;
            }
            Sex = client.Sex.HasValue ? (client.Sex.Value ? Sex.Male : Sex.Female) : Sex.Male;
            About = client.About;
            HomePage = (string.IsNullOrWhiteSpace(client.HomeSiteUrl)==false)?( client.HomeSiteUrl.StartsWith("http://") ? client.HomeSiteUrl : string.Concat("http://", client.HomeSiteUrl)):string.Empty;
            Country = client.Country;
            Countries = new List<SelectListItem> { new SelectListItem { Text = string.Empty, Value = "0" } };
            Countries.AddRange(countries.OrderBy(x => x.Name).Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }));
            SelectedCountryId = client.CountryId.HasValue ? client.CountryId.Value : 0;
            Culture = String.IsNullOrEmpty(client.Culture) ? "en-US" : client.Culture;
            m_Ratin = client.m_Rating;
            m_like = client.m_like;
            m_nlike = client.m_nlike;
            m_Views_anonce = client.m_Views_anonce;
            m_Views_history = client.m_Views_history;
            m_Views_online = client.m_Views_online;
            m_VSM = client.m_VSM;
            c_Ratin = client.c_Rating;
            c_like = client.c_like;
            c_nlike = client.c_nlike;
            c_Views_anonce = client.c_Views_anonce;
            c_Views_history = client.c_Views_history;
            c_Views_online = client.c_Views_online;
            c_VSM = client.c_VSM;
            language = client.language;
            System.Web.Security.MembershipUser msu = System.Web.Security.Membership.GetUser(client.UserId);
            OnTheSite = (msu != null) ? msu.CreationDate.ToShortDateString() : string.Empty;

        }
	}
}